package com.scheduler;

import com.common.constant.Constant;
import com.common.utils.MailUtil;
import com.service.HintService;
import com.service.NodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Configurable
@EnableScheduling
public class MailSch {

    @Autowired
    private MailUtil mailUtil;

//    @Autowired
//    private MailTextService mailTextService;

    @Autowired
    private NodeService nodeService;

    @Autowired
    private HintService hintService;



    /**
     * 发送qq邮件
     */
//    @Scheduled(cron = "0 0/5 * * * *")
//    public void sendMassage(){
//        System.out.println("sendMassage");
//        Wrapper<MailText> wr=new EntityWrapper<>();
//        wr.eq("onoroff",MailText.ON);
//        List<MailText> mailTexts = mailTextService.selectList(wr);
//        if(CollectionUtils.isEmpty(mailTexts)){
//            return;
//        }
//        for (MailText mailText : mailTexts) {
//            Long time = mailText.getTime();
//            //判断当前时间-
//            String rTime = DateFormatUtils.format(new Date(time), "HHmm");
//            String nowTime = DateFormatUtils.format(new Date(), "HHmm");
//            int intOf= Integer.valueOf(nowTime)-Integer.parseInt(rTime);
//            if(0<intOf&&intOf<=5){
//                String text = mailText.getText();
//                String title = mailText.getTitle();
//                try {
////                    MailUtils.sendMail(MailConstant.FROM_QQ,MailConstant.FROM_QQ,title,text);
//                    mailUtil.sendMail("448910412@qq.com"
//                            , title+ DateUtil.getDate_yyyyMMdd(),
//                            text
//                    );
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }

    /**
     * 查询执行时间断，发送通知
     */
    @Scheduled(cron = "0 0/1 * * * *")
    public void send(){
//        nodeService.send();
        if(Constant.SCH_FLAG){
            return;
        }
        hintService.send();
    }


}
